package com.bulemobi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.bulemobi.activity.ac_user_centre.BaseListAdapter;
import com.bulemobi.bean.CarInfoBean;
import com.bulemobi.data.DataCentre;
import com.bulemobi.net.tsz.afinal.FinalBitmap;
import com.jsyh.hcb.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by 武 on 2014/7/21 0021.
 *
 */
public class MyCarAdapter extends BaseListAdapter<CarInfoBean> {

    private String type;
    // 用来控制CheckBox的选中状况
    private static HashMap<Integer,Boolean> isSelected;

    public MyCarAdapter(Context context, ArrayList<CarInfoBean> list,String type) {
        super(context, list);
        this.type = type;
        fb = FinalBitmap.create(context.getApplicationContext());
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        CarInfoBean bean = getItem(position);

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.ac_mycar_item, null);
            assert convertView != null;
            holder.tv_year_protect_data = (TextView) convertView.findViewById(R.id.tv_year_protect_data);
            holder.tv_myCar_insureEndDate = (TextView) convertView.findViewById(R.id.tv_myCar_insureEndDate);
            holder.tv_register_data = (TextView) convertView.findViewById(R.id.tv_register_data);
            holder.tv_engine_no = (TextView) convertView.findViewById(R.id.tv_engine_no);
            holder.tv_no_handle_count = (TextView) convertView.findViewById(R.id.tv_no_handle_count);
            holder.tv_pay_money = (TextView) convertView.findViewById(R.id.tv_pay_money);
            holder.ck_select = (CheckBox) convertView.findViewById(R.id.ck_select);
            holder.iv_carPic = (ImageView) convertView.findViewById(R.id.iv_carPic);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if(type.equals(DataCentre.AC_USERCENTRE)){//隐藏
            convertView.findViewById(R.id.lay_commen).setVisibility(View.GONE);
        }
        holder.tv_carLicense.setText(bean.getCarLicense());
//        holder.tv_year_protect_data.setText(bean.get);
        holder.tv_myCar_insureEndDate.setText(bean.getInsureEndDate());
        holder.tv_register_data.setText(bean.getRegisterDate());
        holder.tv_engine_no.setText(bean.getEngineNo());
        holder.tv_no_handle_count.setText(bean.getRegisterDate());
        //图片
        if(!type.equals(DataCentre.AC_USERCENTRE)){//未处理
            holder.tv_no_handle_count.setText("后台没有参数");//未处理记录数
            holder.tv_pay_money.setText(bean.getDealFee());
        }
        return convertView;
    }

    //缓存对象的类
    private class ViewHolder {
        private TextView tv_carLicense, tv_year_protect_data, tv_myCar_insureEndDate, tv_register_data, tv_engine_no, tv_no_handle_count, tv_pay_money;
        private CheckBox ck_select;
        private ImageView iv_carPic;
    }

    public static HashMap<Integer,Boolean> getIsSelected() {
        return isSelected;
    }

    public static void setIsSelected(HashMap<Integer,Boolean> isSelected) {
        MyCarAdapter.isSelected = isSelected;
    }

}
